Skip to content

Swift Configuration Integration#10

Open
Andrea-Scuderi wants to merge 2 commits intomainfrom
features/swift-configuration
Open

Swift Configuration Integration#10
Andrea-Scuderi wants to merge 2 commits intomainfrom
features/swift-configuration

Conversation

@Andrea-Scuderi
Copy link
Copy Markdown
Member

@Andrea-Scuderi Andrea-Scuderi commented Jan 17, 2026

Overview

This PR integrates Apple's swift-configuration package into the Breeze Lambda DynamoDB API, replacing direct environment variable access with a more flexible, testable configuration system. The changes modernize configuration management while maintaining backward compatibility with existing environment variables.

Key Changes

1. Package Dependencies

File: Package.swift

  • Added swift-configuration package dependency (v1.0.0+)
  • Integrated Configuration product into BreezeLambdaAPI and BreezeLambdaItemAPI targets
  • Enables structured configuration management across the codebase

2. Configuration Layer Refactor

File: Sources/BreezeLambdaAPI/BreezeAPIConfiguration.swift

Protocol Enhancement:

  • Made APIConfiguring protocol Sendable for thread-safety and Swift concurrency compliance

ConfigReader Integration:

  • Replaced direct Lambda.env() calls with ConfigReader supporting multiple providers:
    • EnvironmentVariablesProvider() - runtime environment variables
    • FileProvider<JSONSnapshot> - file-based configuration fallback

Configuration Keys (Strongly-Typed Enum):

  • _HANDLER - Lambda handler identifier
  • AWS_REGION - AWS region configuration
  • DYNAMO_DB_TABLE_NAME - DynamoDB table name
  • DYNAMO_DB_KEY - Primary key configuration
  • LOCALSTACK_ENDPOINT - LocalStack endpoint for local development
  • BREEZE_DB_TIMEOUT - Database timeout in seconds

Dynamic dbTimeout:

  • Changed from static property to dynamic, configurable via BREEZE_DB_TIMEOUT environment variable
  • Default value: 30 seconds
  • Enables runtime tuning without redeployment

Cleaner Region Handling:

  • Simplified region resolution logic with fallback defaults

3. Demo Application Update

File: Sources/BreezeLambdaItemAPI/BreezeLambdaItemAPI.swift

  • Removed hardcoded APIConfiguration struct
  • Implemented multi-provider ConfigReader combining:
    • Environment variables (primary source)
    • JSON configuration file from resources (fallback)
  • Configuration file: Sources/BreezeLambdaItemAPI/Resources/breeze-item-config.json

4. Configuration Resources

New File: Sources/BreezeLambdaItemAPI/Resources/breeze-item-config.json

Defines all configuration parameters for local development and testing with LocalStack integration.

Benefits

Feature Benefit
Flexibility Configuration from environment variables, JSON files, or custom providers
Testability Easier to mock/override configuration in unit and integration tests
Type Safety Strong typing for configuration keys reduces runtime errors
Concurrency Ready Sendable protocol compliance for Swift async/await patterns
Developer Experience JSON-based configuration enables local development without manual env vars
Maintainability Centralized configuration with proper separation of concerns

Backward Compatibility

Fully backward compatible - All changes maintain existing behavior:

  • Environment variables continue to work as primary configuration source
  • Configuration files serve as optional secondary/fallback source
  • No breaking changes to public APIs
  • Existing deployments continue to function without modifications

Testing Recommendations

  • Test environment variable overrides work correctly
  • Test JSON configuration file loading and parsing
  • Test multi-provider fallback behavior
  • Verify BREEZE_DB_TIMEOUT dynamic configuration
  • Test LocalStack integration with new configuration structure
  • Validate Sendable protocol compliance in concurrent contexts

Migration Notes

No migration needed for existing deployments. For teams wanting to leverage the new configuration files:

  1. Create breeze-item-config.json in your Lambda resource directory
  2. Define configuration parameters (environment variables take precedence)
  3. No code changes required - existing deployment methods continue to work

@Andrea-Scuderi Andrea-Scuderi force-pushed the features/swift-configuration branch from 433478e to 3259875 Compare January 17, 2026 14:02
@Andrea-Scuderi Andrea-Scuderi self-assigned this Jan 17, 2026
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 46.15385% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.45%. Comparing base (f3156f8) to head (3259875).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
...urces/BreezeLambdaAPI/BreezeAPIConfiguration.swift 46.15% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #10      +/-   ##
==========================================
+ Coverage   88.22%   88.45%   +0.23%     
==========================================
  Files          14       13       -1     
  Lines         416      381      -35     
==========================================
- Hits          367      337      -30     
+ Misses         49       44       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Andrea-Scuderi Andrea-Scuderi changed the title PR Summary: Swift Configuration Integration Swift Configuration Integration Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants